﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using FlyHorse.LIMS.Model;
using FlyHorse.LIMS.WinApp.Model;
using System.Collections.Generic;
using System.Linq;

namespace FlyHorse.LIMS.WinApp.XtraReportTemplate.ReportProducts
{
    public partial class XtraReportProductBase : DevExpress.XtraReports.UI.XtraReport
    {
        public XtraReportProductBase()
        {
            InitializeComponent();
        }

        public void Transform(ReportProduct report)
        {
            ReportProductPrintModel model = new ReportProductPrintModel();
            model.AddDateTime = report.AddDateTime;
            model.CustomerID = report.CustomerID;
            model.CustomerName = report.Customer.CustomerName;
            model.DateProduced = report.DateProduced;
            model.ExPlant = report.ExPlant;
            model.GoodsID = report.GoodsID;
            model.GoodsName = report.Good.GoodsName;
            model.LoginUserID = report.LoginUserID;
            model.LotNo = report.LotNo;
            model.Remark = report.Remark;
            model.ReportProductID = report.ReportProductID;
            model.ReportProductNO = report.ReportProductNO;
            model.ShippedTo = report.ShippedTo;
            model.TypeOfPack = report.TypeOfPack;
            model.Weight = report.Weight;


            List<ReportProductResultPrintModel> resultList = new List<ReportProductResultPrintModel>();
            foreach (var item in report.ReportProductResults)
            {
                ReportProductResultPrintModel result = new ReportProductResultPrintModel();
                result.Basis = item.Basis;
                result.ChineseName = item.ChineseName;
                result.Conclusion = item.Conclusion;
                result.FormOrder = item.FormOrder;
                result.MaxValue = item.MaxValue;
                result.MinValue = item.MinValue;
                result.ReportProductID = item.ReportProductID;
                result.ReportProductResultID = item.ReportProductResultID;
                result.TestItemID = item.TestItemID;
                result.TestItemNames = item.ChineseName + "\r\n(" + item.TestItem.Remark + ")";
                result.TestValue = item.TestValue;
                result.Unit = item.Unit;
                resultList.Add(result);
            }
            resultList = resultList.OrderBy(m => m.FormOrder).ToList();
            model.ReportProductResults = resultList;
            InitReport(model);
        }

        private void InitReport(ReportProductPrintModel report)
        {

          
        }

    }
}
